package com.hfut.wxy.controller;

import com.hfut.wxy.common.response.Response;
import com.hfut.wxy.common.utils.RedisUtil;
import com.hfut.wxy.entity.mysql.WxyUserInfo;
import com.hfut.wxy.service.ISignService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "登录接口层")
@RestController
@RequestMapping("/sign")
public class SignController {
    @Resource private RedisUtil redisUtil;
    @Resource private ISignService signService;

    @GetMapping("/test")
    public Response test(String v){
        redisUtil.set("token:key",v);
        return Response.success("weqweq");
    }
    @ApiOperation("1 登录")
    @PostMapping("/login")
    public Response sign(@RequestParam String code){
        return Response.success(signService.login(code));
    }

    @ApiOperation("2 信息门户验证")
    @PostMapping("/userVerify")
    public Response verify(@RequestBody WxyUserInfo wxyUserInfo) throws Exception {
        boolean b = signService.verify(wxyUserInfo.getId(),wxyUserInfo.getUsername(),wxyUserInfo.getPassword(),wxyUserInfo.getPhone());
        if (!b){
            return Response.verityFail;
        }
        return Response.success;
    }

    @ApiOperation("3 获取用户信息")
    @PostMapping("/userInfo/{id}")
    public Response getUserInfo(@PathVariable Integer id){
        return Response.success(signService.getUserInfo(id));
    }


}
